Declares a variable or an array.
変数や配列を宣言します。
[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]]
[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]]
Optionally, you can add the Preserve keyword as a parameter to preserve the contents of the array that is redimensioned.
オプションとして Preserve キーワードをパラメータとして使えば、再宣言される配列の内容を保持することが出来ます。
VarName: Any variable or array name.
VarName: 変数ないし配列の名前。
Start, End: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.
Start, End:要素数 (要素の数 = (end-start)+1) とインデックス範囲を定義する数値または定数。
Start and End can be numeric expressions if ReDim is used at the procedure level.
プロシージャーレベルで ReDim を記述する場合は、開始および終了値に数値表式を使用できます。
VarType: Keyword that declares the data type of a variable.
VarType: 変数型を指定するキーワード。
Keyword: Variable type
キーワード: 変数型
Bool: Boolean variable (True, False)
Bool:ブール型変数 (True、False)
Date: Date variable
Date: 日付変数
Double: Double floating point variable (1.79769313486232x10E308 - 4.94065645841247x10E-324)
Double: 倍精度型の浮動小数点変数 (1.79769313486232 × 10E308 から 4.94065645841247 × 10E-324)
Integer: Integer variable (-32768 - 32767)
Integer: 整数変数 (-32768 から 32767)
Long: Long integer variable (-2,147,483,648 - 2,147,483,647)
Long: ロング整数変数 (-2,147,483,648 から 2,147,483,647)
Object: Object variable (can only be subsequently defined by Set!)
Object: オブジェクト変数 (この変数を定義する場合は、Set ステートメントを使用する必要があります)
[Single]: Single floating-point variable (3.402823x10E38 - 1.401298x10E-45). If no key word is specified, a variable is defined as Single, unless a statement from DefBool to DefVar is used.
[Single]: 単精度型の浮動小数点変数 (3.402823 × 10E38 から 1.401298 × 10E-45)。 キーワードを省略した場合、DefBool から DefVar までのステートメントを使用していないかぎり、すべての変数は自動的に単精度型とされます。
String: String variable containing a maximum of 64,000 ASCII characters.
String: 最大 64,000 テキストからなる文字列変数。
Variant: Variant variable type (can contain all types and is set by definition).
Variant: バリアント型変数 (定義によりすべてのデータ型を代入できる変数)。
In Office Basic, you do not need to declare variables explicitly. However, you need to declare an array before you can use them. You can declare a variable with the Dim statement, using commas to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding key word.
Office Basic では、変数を明示的に宣言する必要はありません。 ただし、配列はあらかじめ定義をしておく必要があります。 Dim ステートメントで変数を宣言する場合、コンマで区切ることで複数の宣言を 1 度に行うことができます。 変数のデータ型は、変数名の後に型宣言子またはキーワードを付けることで指定します。
Office Basic supports single or multi-dimensional arrays that are defined by a specified variable type. Arrays are suitable if the program contains lists or tables that you want to edit. The advantage of arrays is that it is possible to address individual elements according to indexes, which can be formulated as numeric expressions or variables.
Office Basic では 1 次元および多次元配列を使用することができ、変数宣言をする際に変数型を指定します。配列は、プログラム中でリストやテーブルを操作する場合に適しています。配列を使用するメリットとして、インデックスを指定することで配列中の各要素にアクセスできる点がありますが、これらのインデックス指定には数値表式や変数が使えます。
There are two ways to set the range of indices for arrays declared with the Dim statement:
Dim ステートメントで宣言する際に、配列の長さ (インデックスの範囲) は下記の2通りの方法で指定できます。
DIM text(20) As String REM 21 elements numbered from 0 to 20
DIM text(20) As String REM 0から 20 の 21 要素
DIM text(5 to 25) As String REM 21 elements numbered from 5 to 25
DIM text(5 to 25) As String REM 5から 25 の 21 要素
DIM text$(-15 to 5) As String REM 21 elements (0 inclusive),
DIM text$(-15 to 5) As String REM 21 要素 (0 を含む)
rem numbered from -15 to 5
rem 範囲は -15 から 5 まで
Variable fields, regardless of type, can be made dynamic if they are dimensioned by ReDim at the procedure level in subroutines or functions. Normally, you can only set the range of an array once and you cannot modify it. Within a procedure, you can declare an array using the ReDim statement with numeric expressions to define the range of the field sizes.
サブルーチンや関数のプロシージャーレベルでReDimにより次元を指定する場合、変数フィールドはそのタイプにかかわらず動的に作成できます。 通常、配列の範囲は1度設定したら、その後変更することはできません。 プロシージャー内部では、ReDim ステートメントを使って配列を宣言する際に、フィールドサイズの範囲指定に数式を使用できます。
Sub ExampleRedim
Sub ExampleRedim
Dim iVar() As Integer, iCount As Integer
Dim iVar() As Integer, iCount As Integer
ReDim iVar(5) As integer
ReDim iVar(5) As integer
For iCount = 1 To 5
For iCount = 1 To 5
iVar(iCount) = iCount
iVar(iCount) = iCount
Next iCount
Next iCount
ReDim iVar(10) As integer
ReDim iVar(10) As integer
For iCount = 1 To 10
For iCount = 1 To 10
iVar(iCount) = iCount
iVar(iCount) = iCount
Next iCount
Next iCount
end sub
end sub